#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=100000, maxm=100000;

namespace my {
    int n, m=0, ind[maxn+1], to[2*maxn-1], link[2*maxn-1], dfn[maxn+1], size[maxn+1],
        indx[maxn+1], indy[maxn+1], linkx[maxm+1], linky[maxm+1], sco[maxm+1][3],
        optn=0, opt[10*maxm+1][3], indo[maxn+1], linko[10*maxm+1], optt[10*maxm+1],
        val[4*maxn+1], tag[4*maxn+1];

    void addSide(int u, int v) {
        m++;
        to[m] = v;
        link[m] = ind[u];
        ind[u] = m;
    }

    void build(int o, int fa) {
        dfn[o] = ++dfn[0];
        size[o] = 1;
        for (int i=ind[o]; i; i=link[i]) {
            if (to[i]!=fa) {
                build(to[i], o);
                size[o] += size[to[i]];
            }
        }
    }

    void pushDown(int o, int l, int r) {
        if (tag[o]) {
            val[o]+=tag[o];
            if (l!=r) tag[o*2]+=tag[o], tag[o*2+1]+=tag[o];
            tag[o]=0;
        }
    }

    void add(int o, int l, int r, int tl, int tr, int tv) {
        if (tl>tr) return;
        pushDown(o, l, r);
        if (l==tl && r==tr) {
            tag[o]+=tv;
            pushDown(o, l, r);
        } else {
            int mid=(l+r)/2;
            if (tl<=mid) add(o*2, l, mid, tl, min(tr, mid), tv);
            else pushDown(o*2, l, mid);
            if (tr>mid) add(o*2+1, mid+1, r, max(tl, mid+1), tr, tv);
            else pushDown(o*2+1, mid+1, r);
            val[o] = max(val[o*2], val[o*2+1]);
        }
    }

    int get(int o, int l, int r, int tl, int tr) {
        if (tl>tr) return 0;
        pushDown(o, l, r);
        if (l==tl && r==tr) return val[o];
        else {
            int mid=(l+r)/2, ret=0;
            if (tl<=mid) ret=max(ret, get(o*2, l, mid, tl, min(tr, mid)));
            if (tr>mid) ret=max(ret, get(o*2+1, mid+1, r, max(tl, mid+1), tr));
            return ret;
        }
    }

    void addOpt(int o, int l, int r, int w, int x) {
        if (l<=r) {
            optn++;
            opt[optn][0]=w, opt[optn][1]=l, opt[optn][2]=r;
            optt[optn] = x;
            linko[optn]=indo[o];
            indo[o]=optn;
        }
    }

    void init(int o, int fa) {
        static int bx[maxn+1], by[maxn+1], sta[maxn+1], flag[maxn+1];
        sta[++sta[0]] = o;
        if (flag[fa]) {
            addOpt(o, 1, dfn[o]-1, flag[fa], 0);
            addOpt(o, dfn[o]+size[o], n, flag[fa], 0);
        }
        for (int i=indx[o]; i; i=linkx[i]) {
            bx[i] = sta[0];

            int x=sco[i][1], y=sco[i][2], w=sco[i][0];
            if (x==y) {
                addOpt(o, 1, dfn[o]-1, w, 0);
                addOpt(o, dfn[o]+size[o], n, w, 0);
                addOpt(o, 1, n, -w, 1);
                flag[o] += sco[i][0];
            } else if (by[i]) {
                int temp=sta[by[i]+1];
                addOpt(o, 1, dfn[temp]-1, w, 0);
                addOpt(o, dfn[temp]+size[temp], n, w, 0);
            } else if (dfn[y]<dfn[o] || dfn[y]>=dfn[o]+size[o]) {
                addOpt(o, dfn[y], dfn[y]+size[y]-1, w, 0);
            }
        }
        for (int i=indy[o]; i; i=linky[i]) {
            by[i] = sta[0];
            if (bx[i]) {
                add(1, 1, n, dfn[o], dfn[o]+size[o]-1, sco[i][0]);
                if (bx[i]!=sta[0]) {
                    addOpt(sta[bx[i]+1], dfn[o], dfn[o]+size[o]-1, -sco[i][0], 0);
                }
            }
        }

        for (int i=ind[o]; i; i=link[i]) {
            if (to[i]!=fa) init(to[i], o);
        }

        for (int i=indx[o]; i; i=linkx[i]) bx[i] = 0;
        for (int i=indy[o]; i; i=linky[i]) by[i] = 0;
        sta[0]--;
    }

    int solve(int o, int fa) {
        for (int i=indo[o]; i; i=linko[i]) {
            if (!optt[i]) {
                add(1, 1, n, opt[i][1], opt[i][2], opt[i][0]);
            }
        }
        int ans=get(1, 1, n, 1, n);
        for (int i=indo[o]; i; i=linko[i]) {
            if (optt[i]) {
                add(1, 1, n, opt[i][1], opt[i][2], opt[i][0]);
            }
        }

        for (int i=ind[o]; i; i=link[i]) {
            if (to[i]!=fa) {
                ans = max(ans, solve(to[i], o));
            }
        }

        for (int i=indo[o]; i; i=linko[i]) {
            add(1, 1, n, opt[i][1], opt[i][2], -opt[i][0]);
        }

        return ans;
    }

    int main() {
        freopen("score.in", "r", stdin);
        freopen("score.out", "w", stdout);

        int m;
        scanf("%d %d", &n, &m);
        for (int i=1; i<n; i++) {
            int u, v;
            scanf("%d %d", &u, &v);
            addSide(u, v), addSide(v, u);
        }
        for (int i=1; i<=m; i++) {
            scanf("%d %d %d", sco[i]+1, sco[i]+2, sco[i]);
            int x=sco[i][1], y=sco[i][2];
            linkx[i]=indx[x], linky[i]=indy[y];
            indx[x]=indy[y]=i;
        }
        build(1, 0);

        init(1, 0);
        printf("%d\n", solve(1, 0));

        fclose(stdin);
        fclose(stdout);
        return 0;
    }
};

int main() {return my::main();};
